<script>
import { xxxLogin } from '@/api/index.js';
export default {
	globalData: {
		IMG_URL: 'https://nabercat.oss-cn-hangzhou.aliyuncs.com/',
		openid: ''
		// userInfo:{}
	},
	onLaunch: function() {
		// 小程序自动更新
		const updateManager = uni.getUpdateManager();
		updateManager.onCheckForUpdate(function(res) {
			// 请求完新版本信息的回调
			console.log(res.hasUpdate);
		});
		updateManager.onUpdateReady(function(res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate();
					}
				}
			});
		});
		updateManager.onUpdateFailed(function(res) {
			// 新的版本下载失败
			uni.showModal({
				title: '已经有新版本了哟~',
				content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
			});
		});
		this.getOpenId();
		console.log('App Launch');
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	},
	methods: {
		userIdentity() {
			//判断用户是否登录并且登录信息是否有效
			if (!uni.getStorageSync('userInfo')) {
				return false;
			} else {
				return true;
			}
		},
		// 获取用户openid
		getOpenId() {
			let $this = this;
			return new Promise(function(resolve, reject) {
				uni.login({
					provider: 'weixin',
					success: loginRes => {
						// 获取openid
						xxxLogin({
							jscode: loginRes.code
						}).then(res => {
							$this.globalData.openid = res.openid;
							resolve();
						});
					}
				});
			});
		}
	}
};
</script>

<style>
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */
page {
	font-family: PingFangSC-Medium, PingFang SC;
	height: 100%;
}
button::after {
	border: none;
}
image {
	display: block;
}
.tabbar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
}
@font-face {
	font-family: 'iconfont'; /* Project id 2694652 */
	src: url('//at.alicdn.com/t/font_2694652_5yh6aubg21q.woff2?t=1627004652091') format('woff2'),
		url('//at.alicdn.com/t/font_2694652_5yh6aubg21q.woff?t=1627004652091') format('woff'),
		url('//at.alicdn.com/t/font_2694652_5yh6aubg21q.ttf?t=1627004652091') format('truetype');
}
.subscribe--live-player-subscribe__btn {
	border-radius: 20rpx !important;
}
</style>
